<?php /*a:2:{s:60:"D:\project\feitu\feitu-backend\app\admin\view\auth\form.html";i:1739783773;s:55:"D:\project\feitu\feitu-backend\app\admin\view\main.html";i:1739783773;}*/ ?>
<div class="layui-card"><style>
    ul.ztree li {
        line-height: 24px;
        white-space: normal !important;
    }

    ul.ztree li span.button.switch {
        margin-right: 5px;
    }

    ul.ztree ul ul li {
        display: inline-block;
        white-space: normal;
    }

    ul.ztree > li {
        border: 1px solid rgba(0, 0, 0, 0.10);
        padding: 15px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 3px;
        margin-bottom: 10px;
    }

    ul.ztree > li > ul {
        padding: 10px;
        margin-top: 10px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 3px;
    }

    ul.ztree > li > ul > li {
        padding: 5px 0;
    }

    ul.ztree > li > a > span {
        font-size: 15px;
        font-weight: 700;
    }

    ul.ztree .level2 .button.level2 {
        width: 0;
    }

    ul.ztree li span.button.noline_open {
        background-position-y: -73px;
    }

    ul.ztree li span.button.noline_close {
        background-position-y: -73px;
    }

    ul.ztree .level1 > .node_name {
        font-weight: bold;
    }
</style><?php if(!(empty($title) || (($title instanceof \think\Collection || $title instanceof \think\Paginator ) && $title->isEmpty()))): ?><div class="layui-card-header"><span class="layui-icon font-s10 color-desc margin-right-5">&#xe65b;</span><?php echo htmlentities((string) lang($title)); ?><div class="pull-right"><button data-target-submit class='layui-btn layui-btn-sm'><?php echo lang('保存数据'); ?></button><button data-target-backup class="layui-btn layui-btn-sm layui-btn-danger"><?php echo lang('取消编辑'); ?></button></div></div><?php endif; ?><div class="layui-card-line"></div><div class="layui-card-body"><div class="layui-card-html"><?php if(!(empty($showErrorMessage) || (($showErrorMessage instanceof \think\Collection || $showErrorMessage instanceof \think\Paginator ) && $showErrorMessage->isEmpty()))): ?><div class="think-box-notify" type="error"><b><?php echo lang('系统提示：'); ?></b><span><?php echo $showErrorMessage; ?></span></div><?php endif; ?><div class="think-box-shadow"><form method="post" id="RoleForm" class="layui-form layui-card"><div class="layui-card-body"><label class="layui-form-item relative block"><span class="help-label"><b><?php echo lang('权限名称'); ?></b>Auth Name</span><input maxlength="100" class="layui-input" name="title" value='<?php echo htmlentities((string) (isset($vo['title']) && ($vo['title'] !== '')?$vo['title']:"")); ?>' required vali-name="<?php echo lang('权限名称'); ?>" placeholder="<?php echo lang('请输入权限名称'); ?>"><span class="help-block"><?php echo lang('访问权限名称需要保持不重复，在给用户授权时需要根据名称选择！'); ?></span></label><label class="layui-form-item relative block"><span class="help-label"><b><?php echo lang('权限描述'); ?></b>Auth Remark</span><textarea placeholder="<?php echo lang('请输入权限描述'); ?>" maxlength="200" class="layui-textarea" name="desc"><?php echo htmlentities((string) (isset($vo['desc']) && ($vo['desc'] !== '')?$vo['desc']:"")); ?></textarea></label><div class="layui-form-item"><span class="help-label label-required-prev"><b><?php echo lang('功能节点'); ?></b>Auth Nodes</span><ul id="zTree" class="ztree notselect"></ul></div><div class="hr-line-dashed"></div><?php if(!(empty($vo['id']) || (($vo['id'] instanceof \think\Collection || $vo['id'] instanceof \think\Paginator ) && $vo['id']->isEmpty()))): ?><input name="id" value="<?php echo htmlentities((string) $vo['id']); ?>" type="hidden"/><?php endif; ?><div class="layui-form-item text-center"><button data-target-submit class="layui-btn"><?php echo lang('保存数据'); ?></button><button data-target-backup class="layui-btn layui-btn-danger" type="button"><?php echo lang('取消编辑'); ?></button></div></div></form></div></div></div><script>
    require(['jquery.ztree'], function () {
        new function () {
            let that = this;
            this.data = {}, this.ztree = null, this.setting = {
                view: {showLine: false, showIcon: false, dblClickExpand: false},
                check: {enable: true, nocheck: false, chkboxType: {"Y": "ps", "N": "ps"}}, callback: {
                    beforeClick: function (id, node) {
                        node.children.length < 1 ? that.ztree.checkNode(node, !node.checked, true, true) : that.ztree.expandNode(node);
                        return false;
                    }
                }
            };
            this.renderChildren = function (list, level) {
                let childrens = [];
                for (let i in list) childrens.push({
                    open: true, node: list[i].node, name: list[i].title || list[i].node,
                    checked: list[i].checked || false, children: this.renderChildren(list[i]._sub_, level + 1)
                });
                return childrens;
            };
            this.syncData = function () {
                $.form.load('<?php echo sysuri(); ?>', {id: '<?php echo htmlentities((string) (isset($vo['id']) && ($vo['id'] !== '')?$vo['id']:0)); ?>', action: 'json'}, 'post', function (ret) {
                    return (that.data = that.renderChildren(ret.data, 1)), that.showTree(), false;
                });
            };
            this.showTree = function () {
                this.ztree = $.fn.zTree.init($("#zTree"), this.setting, this.data);
                while (true) {
                    let nodes = this.ztree.getNodesByFilter(function (node) {
                        return (!node.node && node.children.length < 1);
                    });
                    if (nodes.length < 1) break;
                    for (let i in nodes) this.ztree.removeNode(nodes[i]);
                }
            };
            // 刷新数据
            this.syncData();
            // 监听表单提交
            $('#RoleForm').vali(function (form) {
                let data = that.ztree.getCheckedNodes(true);
                Object.assign(form, {nodes: [], action: 'save'})
                for (let i in data) if (data[i].node) form.nodes.push(data[i].node);
                $.form.load('<?php echo sysuri(); ?>', form, 'post');
            });
        };
    });
</script></div>